package com.example.combwyaq.visualinterface.mainfragment;


import android.Manifest;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;

import android.view.View;

import com.blankj.utilcode.util.PhoneUtils;
import com.example.combwyaq.R;
import com.example.combwyaq.db.DaoManager;
import com.example.combwyaq.entity.UserEntity;
import com.example.combwyaq.mvp.contract.LREContract;
import com.example.combwyaq.mvp.model.HttpCode;
import com.example.combwyaq.mvp.model.entity.BaseEntity;
import com.example.combwyaq.mvp.model.entity.ChannelEntity;
import com.example.combwyaq.mvp.model.entity.TextBannerEntity;
import com.example.combwyaq.mvp.presenter.LREPresenter;
import com.example.combwyaq.mvp.viwe.BaseFragment;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class MainFragment_news extends BaseFragment<LREPresenter> implements LREContract.LREView{


    @Override
    public void refreshAll(BaseEntity entity) {
        if (entity instanceof TextBannerEntity){
            //文字banner返回
        }else if (entity instanceof ChannelEntity){
            //频道列表数据
            //按照频道数量以及频道id初始化fragment
        }

    }

    @Override
    public void refreshRecyclerView(BaseEntity entity) {

    }

    @Override
    public void loadMoreRecyclerView(BaseEntity entity) {

    }


    @Override
    public int bindLayout() {
        return R.layout.fragment_news;
    }

    @Override
    public void initView() {

    }

    @Override
    public void inject() {

    }

    @Override
    public void initData() {
        //获取顶部文字banner数据源
        try {
            List<UserEntity> user = DaoManager.getInstance().getDaoSession().queryBuilder(UserEntity.class).list();
            boolean flag = user.size()== 0;
            Map<String, Object> bannerMap = new HashMap<>();
            bannerMap.put("code", HttpCode.TEXTBANNERCODE);
            Map<String, Object> channelMap = new HashMap<>();
            channelMap.put("code",HttpCode.USERCHANNELCODE);
            if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED){
                return;
            }
            channelMap.put("imie",flag? PhoneUtils.getIMEI():"");
            channelMap.put("userId",flag?0:user.get(0).user_id);
            p.requestAll(bannerMap,channelMap);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
